/**************************************************************************************
 * [Project]
 *       MyProgressDialog
 * [Package]
 *       com.lxd.widgets
 * [FileName]
 *       CustomProgressDialog.java
 * [Copyright]
 *       Copyright 2012 LXD All Rights Reserved.
 * [History]
 *       Version          Date              Author                        Record
 *--------------------------------------------------------------------------------------
 *       1.0.0           2012-4-27         lxd (rohsuton@gmail.com)        Create
 **************************************************************************************/

package com.isunland.managesystem.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;
import com.isunland.managesystem.R;

public class CustomProgressDialog extends Dialog {
  private static CustomProgressDialog customProgressDialog = null;

  public CustomProgressDialog(Context context) {
    super(context);
  }

  public CustomProgressDialog(Context context, int theme) {
    super(context, theme);
  }

  public static CustomProgressDialog createDialog(Context context) {
    customProgressDialog = new CustomProgressDialog(context, R.style.CustomProgressDialog);
    customProgressDialog.setContentView(R.layout.dialog_customprogress);
    customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
    // ##-->Click Settings screen don't disappear
    customProgressDialog.setCanceledOnTouchOutside(false);
    return customProgressDialog;
  }

  public void onWindowFocusChanged(boolean hasFocus) {

    if (customProgressDialog == null) {
      return;
    }

    ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView);
    AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
    animationDrawable.start();
  }

  /**
   * [Summary] setTitile ����
   */
  public CustomProgressDialog setTitile(String strTitle) {
    return customProgressDialog;
  }

  /**
   * [Summary] setMessage ��ʾ����
   */
  public CustomProgressDialog setMessage(String strMessage) {
    TextView tvMsg = (TextView) customProgressDialog.findViewById(R.id.id_tv_loadingmsg);

    if (tvMsg != null) {
      tvMsg.setText(strMessage);
    }

    return customProgressDialog;
  }
}
